package writer;

import java.io.*;

/**
 * @author 培培
 * @condition 努力学习中
 */
public class BufferedCopy_ {
    public static void main(String[] args) {

        //BufferedReader 和 BufferedWriter 是按字符操作
        //不要去操作 二进制文件[视频，声音，doc，PDF 等]，可能会造成文件损坏

        String srcFilePath = "d:\\story.txt";
        String destFilePath = "d:\\story2.txt";
        BufferedReader br = null;
        BufferedWriter bw = null;
        String line;
        try {
            br = new BufferedReader(new FileReader(srcFilePath));
            bw = new BufferedWriter(new FileWriter(destFilePath));

            while ((line = br.readLine()) != null){
                //每读一行，就写入
                bw.write(line);
                //插入一个换行符
                bw.newLine();

            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null){
                    br.close();
                }
                if (bw != null){
                    bw.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
